package com.xhj.config;

import com.xhj.service.StatisticsDailyService;
import com.xhj.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class ScheduledTask {

    @Autowired
    private StatisticsDailyService statisticsDailyService;

    /**
     * 每日1点统计昨日信息
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void task(){
        // 获取上一天的日期
        String day = DateUtil.formatDate(DateUtil.addDays(new Date(), -1));
        statisticsDailyService.statisticsByDay(day);
    }
}
